<?php


namespace app\common\model;
use think\Model;
use think\Db;
class Master extends Model
{
    protected $table = "store_member";

    public function lists($param){
        $user = self::where(["id"=>$param['user_id']])->field("id,username,headimg,nickname,openid,id,phone")->find();

        $station = Db::table("store_power_station")->where(["user_id"=>$user['id']])->field("id")->find();
        $park = Db::table("store_park")->where(["user_id"=>$user['id']])->field("id")->find();

        $user['is_station'] = 0;
        $user['is_park'] = 0;

        if($station){
            $user['is_station'] = 1;
        }
        if($park){
            $user['is_park'] = 1;
        }

        $user['order_charge'] = Db::table("store_yinuo_order")->where(['user_id'=>$user['id'],'type'=>1])->where("status=1")->count();
        $user['order_charge_already'] = Db::table("store_yinuo_order")->where(['user_id'=>$user['id'],'type'=>1])->where("status=2")->count();
        $user['order_charge_ing'] = Db::table("store_yinuo_order")->where(['user_id'=>$user['id'],'type'=>1])->where("status","in","3,4")->count();
        $user['order_charge_complete'] = Db::table("store_yinuo_order")->where(['user_id'=>$user['id'],'type'=>1])->where("status","in","5,6")->count();
        $user['order_park'] = Db::table("store_yinuo_order")->where(['user_id'=>$user['id'],'type'=>2])->where("status=1")->count();
        $user['order_park_already'] = Db::table("store_yinuo_order")->where(['user_id'=>$user['id'],'type'=>2])->where("status","in","2,3")->count();
        $user['order_park_ing'] = Db::table("store_yinuo_order")->where(['user_id'=>$user['id'],'type'=>2])->where("status","in","4")->count();
        $user['order_park_complete'] = Db::table("store_yinuo_order")->where(['user_id'=>$user['id'],'type'=>2])->where("status","in","5,6")->count();

        $user['income_charge'] = sprintf('%.2f',Db::table("store_fenyong")->where(['user_id'=>$user['id']])->sum('charge_price')+Db::table("store_fenyong")->where(['user_id'=>$user['id']])->sum('service_price'));
        $user['income_park'] = sprintf('%.2f',Db::table("store_fenyong")->where(['user_id'=>$user['id']])->sum('park_price'));

        //$user['total_income'] = sprintf('%.2f',$user['income_charge']+$user['income_park']);


        $user['total_income'] =  sprintf('%.2f',Db::table("store_fenyong")->where(['user_id'=>$user['id']])->sum('amount'));
        $user['amount'] =  sprintf('%.2f',Db::table("store_fenyong")->where("is_jiesuan=0")->where(['user_id'=>$user['id']])->sum('amount'));



        return $user;
    }

}